/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			mdic_basic.h
  \date			Sep 2011
  \author		TNick

  \brief		Contains the definition for basic interaction in mdi window


  Copyright (c) 2011, Nicu Tofan
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
	* Redistributions of source code must retain the above copyright
	  notice, this list of conditions and the following disclaimer.
	* Redistributions in binary form must reproduce the above copyright
	  notice, this list of conditions and the following disclaimer in the
	  documentation and/or other materials provided with the distribution.
	* Neither the name of the copyright holder nor the
	  names of its contributors may be used to endorse or promote products
	  derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL NICU TOFAN BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __MDICHILD_BASIC_INC__
#define __MDICHILD_BASIC_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */
	//
	//
	//
	//
	/*  DATA         ------------------------------------------------------- */

private:
	/// full path and name for the file hosted by this document
	QString                 cur_file;

	/// tell if this is a new file or one loaded form disk
	bool                    is_untitled;

	/// tell if the document was modified (and, this, needs saving)
	bool                    is_modified;

	/* some systems (like symbian) have no support for printing */
#ifndef QT_NO_PRINTER
	/// printer configuration structure
	QPrinter    printer;
#endif

	/*  DATA         ======================================================= */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */


public:

	/// initialises the instance to represent a new document
	void        newFile                     ( void );

	/// allows for browsing and loads the file in the instance
	bool        loadFile                    (const QString &fileName);

	/// high level; saves the document (may call saveAs())
	bool        save                        ( void );

	/// shows a dialog allowing to select where to save the document
	bool        saveAs                      ( void );

	/// effectively saving the file
	bool        saveFile                    (const QString &fileName);

	/// strips the path from file name
	QString     userFriendlyCurrentFile     ( void )
	{ return strippedName(cur_file); }

	/// tells the full path and name of the file hosted by this document
	QString     currentFile                 ( void )
	{
		if (is_untitled)
			return QString();
		else
			return cur_file;
	}

	/// tell if this document has anything selected
	bool        hasSelection                ( void )
	{ return false; }

	/// undo last action in document
	void        undo            	( void ) ;


	/// redo last action in document
	void        redo            	( void ) ;

	/// cut the selection
	void        cut                 ( void ) {}

	/// copy the selection
	void        copy            	( void ) {}

	/// paste content of the clipboard
	void        paste            	( void ) {}

	/// delete the selection
	void        delSel           	( void ) {}

	/// select entire content of the document
	void        selAll            	( void ) {}

	/// presents the print dialog; user is allowed to print
	void        printDialog         ( void );

	/// presents the page setup dialog
	void        pageSetupDialog     ( void );

	/// preview printed document
	void        printPreviewDialog  ( void );

	/// actually do the printing
	void        print               ( void );



private slots:

	/// central point that is informed about changes
	void        documentWasModified ( void )
	{ is_modified = true; }



signals:

	/// raised when saving under a different name
	void        nameChanged         ( void );
	/// raised when something is selected / the selection is cleared
	void        selStateChange      ( void );
	/// raised when a document is closed
	void        docClosed           (MdiChild* p_closed);

protected:
	/// reimplements the event to allow saving the changes
	void        closeEvent          (QCloseEvent *event);


private:

	/// dialog based routine to decide if closing may proceed
	bool        maybeSave           ( void );

	/// save the path and name of the file; set internal state
	void        setCurrentFile      (const QString &fileName);

	/// strips the path from file name
	QString     strippedName        (const QString &fullFileName)
	{ return QFileInfo(fullFileName).fileName(); }


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//


/*  CLASS    =============================================================== */
//
//
//
//
#endif // __MDICHILD_BASIC_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
